package stream01;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Stream流的概述
 *   统计集合中后缀名为.txt文件名称的个数
 *
 */
public class StreamDemo01 {
	@Test
	public void test01() {
		ArrayList<String> al = new ArrayList<String>();
		al.add("1.txt");
		al.add("2.txt");
		al.add("3.pdf");
		al.add("4.docx");
		int count=0;//定义一个计数器
		for (String s : al) {
			if (s.endsWith(".txt")) {
				count++;
			}
		}
		System.out.println(count);
	}

	@Test
	public void test02() {
		List<String> list = Arrays.asList("1.txt", "2.txt", "3.pdf", "4.docx");
		//long count = list.stream().filter(str -> str.endsWith(".txt")).count();
		//System.out.println(count);
		System.out.println(list.stream().filter(str -> str.endsWith(".txt")).count());
	}
}
